﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanmia.Core;
using Tanmia.Basis;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Linq;

namespace Tanmia.NHibernate
{
    public class ColorRepository : Repository<Color>
    {
        public IList<Color> Gets(Item item)
        {
            ISession session = SessionFactory.Session;

            var subQuery = QueryOver.Of<DiscriminatedItem>()
                .Where(x => x.Item.ItemID == item.ItemID)
                .Select(x => x.Color.ColorID);

            var result = session.QueryOver<Color>()
                .WithSubquery.WhereProperty(x => x.ColorID).In(subQuery)
                .List<Color>();

            return result;
        }
    }
}
